package gui;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import negocio.Area;
import negocio.AreaControlador;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class AreaCrear extends JFrame {

	private JPanel contentPane;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AreaCrear frame = new AreaCrear();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public AreaCrear(CursosCrear padre) {
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e){
				padre.nullareaCrear();
			}
		});		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 277, 170);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		this.setTitle("Crear area");
		
		JLabel lblNuevoArea = new JLabel("Nuevo Area");
		lblNuevoArea.setBounds(10, 44, 67, 14);
		contentPane.add(lblNuevoArea);
		
		textField = new JTextField();
		textField.setBounds(87, 41, 164, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				padre.nullareaCrear();
				dispose();
			}
		});
		btnCancelar.setBounds(162, 98, 89, 23);
		contentPane.add(btnCancelar);
		
		JButton btnAceptar = new JButton("Aceptar");
		btnAceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				AreaControlador.guardar(new Area(textField.getText()));
				padre.llenarCombo();
				textField.setText("");
				dispose();
			}
		});
		btnAceptar.setBounds(63, 98, 89, 23);
		contentPane.add(btnAceptar);
	}

}
